const { AsyncParallelHook } = require('tapable')

let hook = new AsyncParallelHook(['name']);

// hook.tap('fn1', function (name) {
//   console.log('fn1:', name)
// })
// hook.tap('fn2', function (name) {
//   console.log('fn2:', name)
// })

// hook.callAsync('abc', function () {
//   console.log(`111`)
// })

//---------------settimeout--------------
// console.time('time1')
// hook.tapAsync('tapAsync1', function (name, callback) {
//   setTimeout(() => {
//     console.log(`tapAsync1:`, name)
//     callback();
//   }, 1000)
// })
// hook.tapAsync('tapAsync2', function (name, callback) {
//   setTimeout(() => {
//     console.log(`tapAsync2:`, name)
//     callback();
//   }, 2000)
// })

// hook.callAsync('setTimeout', function () {
//   console.timeEnd('time1')
// })

//-----------------promise---------------------
console.time('time2')
hook.tapPromise('tapPromise1', function (name) {
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      console.log(`tapPromise1:`, name)
      resolve()
    }, 1000)
  })
})
hook.tapPromise('tapPromise2', function (name) {
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      console.log(`tapPromise2:`, name)
      resolve()
    }, 2000)
  })
})

hook.callAsync('promise', function () {
  console.timeEnd('time2')
})